<?php

namespace app\common\model;

use think\model\concern\SoftDelete;

class RobotConversationMessage extends \think\Model
{
    use SoftDelete;

    protected $table = 'db_robot_conversation_message';

    protected $jsonAssoc = true;

    protected $autoWriteTimestamp = true;

    protected $schema = [
        'id' => 'int',
        'create_time' => 'int',
        'update_time' => 'int',
        'delete_time' => 'int',
        'pubid' => 'varchar',
        'robot_conversation_id' => 'int',
        'user_questions' => 'text',
        'machine_answer' => 'text',
        'referenced_files' => 'json',
        'is_positive_reviews' => 'tinyint',
        'robot_id' => 'int',
        'answer_time' => 'int',
        'event_id' => 'int',
        'is_event_submission' => 'tinyint',
        'event_details' => 'json',
        'user_submission' => 'json',
        'similarity' => 'double',
    ];

    protected $json = [
        'referenced_files',
        'event_details',
        'user_submission',
    ];

    public $getters = [
        
    ];

    /**
     * 关联模型openaiUsage
     */
    public function openaiUsage()
    {
        return $this->hasMany(OpenaiUsage::class );
    }

    /**
     * 关联模型robotAnalysis
     */
    public function robotAnalysis()
    {
        return $this->hasMany(RobotAnalysis::class );
    }

    /**
     * 关联模型robotConversation
     */
    public function robotConversation()
    {
        return $this->belongsTo(RobotConversation::class );
    }

    /**
     * 关联模型robot
     */
    public function robot()
    {
        return $this->belongsTo(Robot::class );
    }

    /**
     * 回答时间设置器
     */
    public function setAnswerTimeAttr($value, $data)
    {
        return $value?strtotime($value):0;
    }
}
